<template>
	<view class="page">
		<view class="flex benben-position-layout flex flex-wrap align-center personalInformation_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub personalInformation_fd0_0'>
				<view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  personalInformation_fd0_0_c0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">&#xE794;</text>
				</view>
				<text class='personalInformation_fd0_0_c1'>会员列表</text>
				<view class='flex flex-wrap align-center personalInformation_fd0_0_c2'>
				</view>
			</view>
		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<u-sticky bg-color="transparent" :offset-top="88+StatusBarRpx">
			<view class="search_view flex align-center justify-between">
				<view class="search_input flex align-center">
					<image :src='STATIC_URL+"451.png"' mode="aspectFill"></image>
					<input v-model="keyword" class="input" type="text" placeholder="输入手机号查询..." placeholder-style="font-size:30rpx;color:#999;" @confirm="getSearch">
				</view>
				<template v-if="userInfo.customer_id == 1">
					<view v-if="userInfo.role != 3" class="add_btn flex align-center justify-center" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/my/personalInformation/addPhone`">
						<image :src='STATIC_URL+"450.png"' mode="aspectFill"></image>
						<text>添加会员</text>
					</view>
				</template>
				<template v-else>
					<view class="add_btn flex align-center justify-center" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/my/personalInformation/addPhone`">
						<image :src='STATIC_URL+"450.png"' mode="aspectFill"></image>
						<text>添加会员</text>
					</view>
				</template>
			</view>
		</u-sticky>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#1A66FA"></u-loading>
			<view>加载中</view>
		</view>
		<template v-else>
			
			<view class="list">
				<view class="list_item flex align-center" v-for="(item, index) in list" :key="index" @tap.stop="selectPerson(item.id, item.is_auth)">
					<image v-if="item.photo" class="item_img" :src='item.photo' mode="aspectFill"></image>
					<image v-else class="item_img" :src='STATIC_URL+"237.png"' mode="aspectFill"></image>
					<view class="item_content flex">
						<view class="item_le flex-sub">
							<view class="item_le_top flex align-center">
								<view class="item_le_top_1">{{item.username}}</view>
								<view class="item_le_top_2" v-if="item.is_auth == 1">
									<text class="item_le_top_4">已认证</text>
								</view>
								<view class="item_le_top_3" v-else>
									<text class="item_le_top_4">待完善</text>
								</view>
								
							</view>
							<view class="item_le_bot">{{item.phone_no}}</view>
						</view>
						<view class="flex flex-direction">
							<!-- <view class="user_order flex align-center justify-center" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/index/memberList/userOrder?user_id=${item.id}`">
								<image :src='STATIC_URL+"496.png"' mode="aspectFill"></image>
								<text>订单</text>
							</view> -->
							<view class="item_ri flex align-center justify-center" @tap.stop="getPhone(item.phone_no)">
								<image :src='STATIC_URL+"452.png"' mode="aspectFill"></image>
								<text>拨打</text>
							</view>
							<view class="item_ri_1" v-if="userInfo.customer_id == 2">{{item.create_at}}</view>
						</view>
						
					</view>
				</view>
				<view class="loadmore" v-if="last_page > 1">
					<u-loadmore font-size="24" :status="status" :icon-type="iconType" :load-text="loadText" />
				</view>
			</view>
			<view class="noData" v-if="list.length == 0 && !isShow">
				<image :src='STATIC_URL+"no.png"'></image>
			</view>
		</template>
		
		<u-modal v-model="addShow" content="请核对手机号是否正确,确认添加此用户吗？" :show-cancel-button="true" confirm-color="#1A66FA" @confirm="addNext"></u-modal>
	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},

		data() {
			return {
				"keyword": "",
				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": true,
				"userInfo": {},
				"type": 1,  // 1新增订单  2会员管理
				"is_search": 1,  // 是否搜索
				"addShow": false,
			};
		},
		computed: {
			
		},
		watch: {},
		onLoad(options) {
			let {type} = options;
			if (type !== undefined) this.type = type;
			this.userInfo = global.userInfo;
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getRegisterPerson();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			
		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getRegisterPerson();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {
		
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getRegisterPerson();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			// 注册的会员列表  postRegister
			getRegisterPerson() {
				this.$api.get(global.apiUrls.postRegister, {
					page: this.page,
					rows: 10,
					phone: this.keyword,
					customer_id: global.userInfo.customer_id
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.totalPage;
						if (this.is_pull) {
							this.list = res.data.data.items;
						} else {
							this.list = this.list.concat(res.data.data.items);
						}
						if (this.list.length == 0) {
							if (this.is_search == 2) {
								if (this.type == 1) {
									this.addShow = true;
									this.is_search = 1;
								}
							}
						}
					} else {
						this.$message.info(res.data.info);
					}
				}).catch(err => {
					console.log(err);
				})
			},
			addNext() {
				this.$api.post(global.apiUrls.addUser, {
					phone_no: this.keyword,
					customer_id: global.userInfo.customer_id
				}).then(result => {
					this.$message.info(result.data.info);
					if (result.data.code == 1) {
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/index/selectVehicle/selectVehicle?user_id=' + result.data.data.user_id
							})
						}, 800)
					}
				}).catch(err => {
					uni.hideLoading();
					this.$message.info(err.info);
				})
			},
			// 搜索
			getSearch() {
				this.is_search = 2;
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getRegisterPerson();
			},
			// 拨打电话
			getPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone //仅为示例
				});
			},
			// 选择用户
			selectPerson(user_id, is_auth) {
				if (this.type == 1) {
					uni.navigateTo({
						url: '/pages/index/selectVehicle/selectVehicle?user_id=' + user_id
					})
					// if (is_auth == 0) {
					// 	this.$message.info('请完善会员信息');
					// 	setTimeout(() => {
					// 		uni.navigateTo({
					// 			url: '/pages/my/personalInformation/personalInformation?user_id=' + user_id
					// 		})
					// 	}, 800)
					// } else {
					// 	uni.navigateTo({
					// 		url: '/pages/index/selectVehicle/selectVehicle?user_id=' + user_id
					// 	})
					// }
				} else {
					uni.navigateTo({
						url: '/pages/my/personalInformation/personalInformation?user_id=' + user_id
					})
				}
			},
		}
	};
</script>
<style lang="scss" scoped>
	.search_view {
		margin: 10rpx 24rpx 16rpx;
		.search_input {
			flex: 1;
			height: 80rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			position: relative;
			padding: 0 24rpx 0 78rpx;
			image {
				position: absolute;
				left: 28rpx;
				top: 50%;
				transform: translateY(-50%);
				width: 25rpx;
				height: 25rpx;
			}
			.input {
				font-size: 30rpx;
			}
		}
		.add_btn {
			width: 212rpx;
			height: 80rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #222222;
			margin-left: 20rpx;
			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 10rpx;
			}
		}
	}
	.list {
		padding: 0 24rpx 16rpx;
		.list_item {
			background: #fff;
			border-radius: 16rpx;
			padding: 30rpx 24rpx;
			margin-top: 16rpx;
			.item_img {
				width: 104rpx;
				height: 104rpx;
				border-radius: 50%;
			}
			.item_content {
				margin-left: 22rpx;
				position: relative;
				flex: 1;
				.item_le {
					.item_le_top {
						.item_le_top_1 {
							font-weight: bold;
							font-size: 36rpx;
							color: #222222;
							margin-right: 12rpx;
						}
						.item_le_top_2 {
							display: inline-block;
							text-align: center;
							line-height: 40rpx;
							width: 90rpx;
							height: 40rpx;
							background: #1A66FA;
							border-radius: 8rpx;
							font-weight: 400;
							font-size: 22rpx;
							color: #FFFFFF;
							margin-left: 10rpx;
							transform:skewX(-8deg);
						}
						.item_le_top_3 {
							display: inline-block;
							text-align: center;
							line-height: 40rpx;
							width: 90rpx;
							height: 40rpx;
							background: #FF792E;
							border-radius: 8rpx;
							font-weight: 400;
							font-size: 22rpx;
							color: #FFFFFF;
							margin-left: 10rpx;
							transform:skewX(-8deg);
						}
						.item_le_top_4 {
							display: inline-block;
							transform: skewX(8deg);
						}
					}
					.item_le_bot {
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
						margin-top: 16rpx;
					}
				}
				.item_ri {
					width: 156rpx;
					height: 48rpx;
					background: #EEF4FF;
					border-radius: 44rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #1A66FA;
					margin-left: auto;
					// margin-top: 14rpx;
					// margin-top: 40rpx;
					// transform: translateY(12rpx);
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 6rpx;
					}
				}
				.item_ri_1 {
					font-size: 24rpx;
					color: #666666;
					margin-top: 16rpx;
				}
				.user_order {
					width: 156rpx;
					height: 48rpx;
					background: #EEF4FF;
					border-radius: 44rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #1A66FA;
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 6rpx;
					}
				}
			}
		}
	}

	.personalInformation_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 100rpx;
	}

	.personalInformation_picker2_0_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #BFBFBF;
	}

	.personalInformation_picker2_0_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
	}

	.personalInformation_picker2_0_c2 {
		color: rgba(44, 143, 255, 1);
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
	}

	.personalInformation_fd1_0 {
		// margin-top: 32rpx;
		height: 96rpx;
		border-top: 1px solid #eee;
	}

	.personalInformation_fd1_0_c0 {
		font-weight: 400;
		font-size: 28rpx;
		color: rgba(0,0,0,0.6);
	}

	.personalInformation_fd1_0_c1_image {
		width: 72rpx;
		height: 72rpx;
		border-radius: 50%;
	}

	.personalInformation_fd1_1 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_1_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_1_c1 {
		font-weight: 400;
		font-size: 28rpx;
		color: #222222;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_2 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_2_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_2_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_3 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_3_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_3_c1 {
		font-weight: 500;
		font-size: 28rpx;
		color: rgba(0,0,0,0.8);
	}

	.personalInformation_flex_1 {
		background: #fff;
		border-radius: 16rpx;
		padding: 24rpx 24rpx 0rpx 24rpx;
		margin: 16rpx 24rpx 0;
	}

	.personalInformation_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.personalInformation_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #111;
	}

	.personalInformation_fd0_0_c1 {
		font-size: 32rpx;
		font-weight: bold;
		color: #111111;
	}

	.personalInformation_fd0_0_c2 {
		width: 36rpx;
		height: 36rpx;
	}

	.personalInformation_flex_0 {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background: url(https://speed.zhongchuxing.com/gjdimages/page_bg.png) no-repeat;
		background-size: 100% auto !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: url(https://speed.zhongchuxing.com/gjdimages/page_bg.png) no-repeat #f6f7fb;
		background-size: 100% auto !important;
	}
</style>